<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/jsp/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jqGird</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/plugins/h+/css/plugins/webuploader/webuploader.css">
    <link href="${ctxStatic}/plugins/h+/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <style>
        .ml10 {
            margin-left: 15px;
        }

    </style>

</head>

<body class="gray-bg" >
<div class="wrapper wrapper-content  animated fadeInRight" id="ccbb">
    <div class="row">
        <div class="col-sm-12">
            <div class="toolbar">
                <div id="toolbar">
                    <button id="btn_add" class="btn btn-primary"><i class="fa fa-plus-circle"></i>&nbsp;新增</button>

                </div>
            </div>
            <span id="spancc" class="spancc"></span>
            <div class="row">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>搜索条件</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content" >
                        <div class="row">
                            <div class="col-md-2"><input placeholder="名称" id="search_customer" class="form-control"></div>
                            <div class="col-md-1"><button id="btn_search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;搜索</button></div>
                        </div>
                    </div>
                </div>
            </div>
            <table id="exampleTablePagination"></table>
        </div>
    </div>
</div>
<form name="form2" id="form2" method="post" action="${pageContext.request.contextPath}/offlineCard/doNull.ac"></form>
</body>
<script src="${ctxStatic}/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
<script src="${ctxStatic}/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/bootstrap-table.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/locale/bootstrap-table-zh-CN.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/extensions/export/bootstrap-table-export.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/extensions/editable/bootstrap-table-editable.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/layer/laydate/laydate.js"></script>
<script>

</script>
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
<script type="text/javascript">
    var ajaxpath='${pageContext.request.contextPath}';
    //初始化表格对象
    var $table = $('#exampleTablePagination');
    /*
     获取选中行的相关数据
     */
    $(function () {
        $table.on('click-row.bs.table', function (e, row, $element) {
            $('.success').removeClass('success');
            $($element).addClass('success');
        });
        $('#button').click(function () {
            alert('Selected name: ' + getSelectedRow().customer);
        });
    });
    function getSelectedRow() {
        var index = $table.find('tr.success').data('index');
        return $table.bootstrapTable('getData')[index];
    }





    ////////////////////////////////////////////////////////////////////////////////////////以下是通过js方式初始化BootStrapTable/////////////////////////////////////////////

    $table.bootstrapTable({
        url: ajaxpath+"/offlineCard/showOfflineCard.ac",
        method: 'post',
        contentType: "application/x-www-form-urlencoded",//必须的
        dataType: "json",
        pageList:[10, 20, 50, 100],//会根据当前的数据量加载合适的pageList
        height: ($(window).height()-200) ,
        //cardView:true,//是否自适应手机
        pagination: true, //分页
        // queryParamsType: "limit",
        singleSelect: false,
        cache:false,
        sortName:"name",
        search: false, //显示搜索框
        showColumns:false,
        showRefresh:false,
        showToggle:false,
        showPaginationSwitch:false,
        smartDisplay:true,
        detailView:false,
        toolbar:"#toolbar",
        queryParams: queryParams,//参数
        searchOnEnterKey:true,
        detailFormatter:function(index, row, element){
            return row.customer;
        },
        sidePagination: "server", //服务端处理分页
        columns: [
            {
                visible:false,
                field:'id'
            },
            //{
           //     title:'选择',
           //     align:'center',
           //     checkbox:true
           // },
            {
                title: '代理商',
                field: 'agent_name',
                sortStable:true,
                align: 'center'
            },
            {
                title: '名称',
                field: 'name',
                sortStable:true,
                align: 'center'
            },
            {
                title: '券额',
                field: 'cardTotal',
                align: 'center',
                formatter:function(value,row,index){
                    return value/100;
                }
            },
            {
                title: '数量',
                field: 'cardCount',
                sortStable:true,
                align: 'center'
            },
            {
                title: '可发放数量',
                field: 'leftCount',
                sortStable:true,
                align: 'center'
            },
            {
                title: '已使用数量',
                field: 'cardUseCount',
                sortStable:true,
                align: 'center'
            },
            {
                title: '操作人',
                field: 'person_name',
                sortStable:true,
                align: 'center'
            },
            {
                title: '添加时间',
                field: 'createTime',
                sortStable:true,
                align: 'center'
            },
            {
                title: '操作',
                align: 'center',
                events:{
                    'click .edit': function (e, value, row, index) {
                        // alert('You click edit icon, row: ' + JSON.stringify(row));
                        //弹出编辑层
                        //showPopup(row.id);
                    },
                    'click .MaKu': function (e, value, row, index) {
                        //alert("码库");
                        showCardDetailPopup(row.id);
                    },
                    'click .XiaZai': function (e, value, row, index) {
                        //alert("下载");
                        downLoad(row.id);
                    },
                    'click .FaFang': function (e, value, row, index) {
                        //alert("发放");
                        showfafangPopup(row.id);
                    },
                    'click .fafangrecord': function (e, value, row, index) {
                        //alert("发放");
                        showfafangrecordPopup(row.id);
                    }
                },
                formatter:function(value,row,index){
                    return [
                        /*'<a class="edit ml10" href="javascript:void(0)" title="编辑">',
                        '<i class="glyphicon glyphicon-edit"></i>',
                        '</a>',*/
                        '<a class="MaKu ml10" href="javascript:void(0)" title="码库">',
                        '<i class="glyphicon glyphicon-folder-close">码库</i>',
                        '</a>',
                        '<a class="XiaZai ml10" href="javascript:void(0)" title="下载">',
                        '<i class="glyphicon glyphicon-download-alt">下载</i>',
                        '</a>',
                        '<a class="FaFang ml10" href="javascript:void(0)" title="发放">',
                        '<i class="glyphicon glyphicon-barcode">发放</i>',
                        '</a>',
                        '<a class="fafangrecord ml10" href="javascript:void(0)" title="发放记录">',
                        '<i class="glyphicon glyphicon-film">发放记录</i>',
                        '</a>'
                    ].join('');
                }
            }
        ]
    });

    /*
     搜索按钮
     */
    $("#btn_search").click(function(){
        $table.bootstrapTable('selectPage', 1);
        $table.bootstrapTable('refresh', queryParams);
    });

    /*
     传递的参数
     */
    function queryParams(params) {
        var name=$("#search_customer").val();
        var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            limit: params.limit,  //页面大小
            offset: params.offset, //页码
            pageindex:params.pageNumber,
            name: name
        };
        return temp;
    };
    ///////////////////////////////////////////////////////////////跳转///////////////////////////////////////
    //新增
    $("#btn_add").click(function(){
        showPopup('');
    })

    //下载
    function downLoad(id) {
        $.ajax({
            url: ajaxpath+'/offlineCard/checkIsSuccess.ac',// 跳转到 action
            data: {id:id},
            type: 'post',
            cache: false,
            dataType: 'json',
            success: function (data) {
                if(data==1){
                    //生成成功,可以下载
                    form2.action = ajaxpath+"/offlineCard/doExcel.ac?id="+id;
                    form2.submit();
                    form2.action = ajaxpath+"/offlineCard/doNull.ac";
                }else{
                    bootbox.alert("实体卡正在生成,请耐心等待！", null);
                }
            },
            error: function () {
                alert("操作失败！");
            }
        });

    }

    //新增
    function showPopup(id){
        //自定页
        parent.layer.open({
            type: 2,
            shift:4,//动画类型
            moveType:1,
            maxmin: true,
            shadeClose: true, //开启遮罩关闭
            area: ['800px', '530px'],
            content: ajaxpath+'/offlineCard/toCardAddEdit.ac?id='+id,
            success: function(layero, index){
                //调用成功执行
                //$table.bootstrapTable('refresh', queryParams);
                return true;
            },
            cancel: function(index){
                $table.bootstrapTable('refresh', queryParams);
                return true;
            },
            close  : function(index){
                return true;
            }
        });
    }

    //发放
    function showfafangPopup(id){
        if(isNullOrEmpty(id)){
            alert("未获取到选中code");
            return;
        }
        //自定页
        parent.layer.open({
            type: 2,
            shift:4,//动画类型
            moveType:1,
            maxmin: true,
            shadeClose: true, //开启遮罩关闭
            area: ['800px', '530px'],
            content: ajaxpath+'/offlineCard/toGrand.ac?id='+id,
            success: function(layero, index){
                //调用成功执行
                //$table.bootstrapTable('refresh', queryParams);
                return true;
            },
            cancel: function(index){
                return true;
            },
            close  : function(index){

                $table.bootstrapTable('refresh', queryParams);
            }
        });
    }


    //查询码库
    function showCardDetailPopup(id){
        if(isNullOrEmpty(id)){
            alert("未获取到选中code");
            return;
        }
        //自定页
        parent.layer.open({
            type: 2,
            shift:4,//动画类型
            moveType:1,
            maxmin: true,
            shadeClose: true, //开启遮罩关闭
            area: ['1000px', '530px'],
            content: ajaxpath+'/offlineCard/toCardDetail.ac?id='+id,
            success: function(layero, index){
                //调用成功执行
                //$table.bootstrapTable('refresh', queryParams);
                return true;
            },
            cancel: function(index){
                return true;
            },
            close  : function(index){

                $table.bootstrapTable('refresh', queryParams);
            }
        });
    }



    //查询发放记录
    function showfafangrecordPopup(id){
        if(isNullOrEmpty(id)){
            alert("未获取到选中code");
            return;
        }
        //自定页
        parent.layer.open({
            type: 2,
            shift:4,//动画类型
            moveType:1,
            maxmin: true,
            shadeClose: true, //开启遮罩关闭
            area: ['1000px', '530px'],
            content: ajaxpath+'/offlineCard/toCardGrandDetail.ac?id='+id,
            success: function(layero, index){
                //调用成功执行
                //$table.bootstrapTable('refresh', queryParams);
                return true;
            },
            cancel: function(index){
                return true;
            },
            close  : function(index){

                $table.bootstrapTable('refresh', queryParams);
            }
        });
    }

    ////////////////////////////公共方法////////////////////////////////
    //true:是空 false:不为空
    function isNullOrEmpty(strVal) {
        if (strVal == null || strVal == undefined || strVal == '') {
            return true;
        } else {
            return false;
        }
    }


</script>



</html>
